package demo;

import org.noear.folkmq.FolkMQ;
import org.noear.folkmq.client.MqClient;
import org.noear.folkmq.client.MqClientDefault;
import org.noear.folkmq.client.MqMessage;

import java.util.Date;

/**
 * @author noear
 * @since 1.0
 */
public class ClientDemo1 {
    public static void main(String[] args) throws Exception {
        //客户端
        MqClient client = FolkMQ.createClient("folkmq://127.0.0.1:18602?ak=folkmq&sk=YapLHTx19RlsEE16")
                .connect();

        //订阅
        client.subscribe("demo", "a", ((message) -> {
            System.out.println("ClientDemo1::" + message);
        }));

        //发布
        for (int i = 0; i < 10; i++) {
            Thread.sleep(100);
            client.publishAsync("demo", new MqMessage("hi-" + i));
            client.publishAsync("demo2", new MqMessage("hi-" + i));
        }

        //延迟五秒
        client.publishAsync("demo3", new MqMessage("hi-d").scheduled(new Date(System.currentTimeMillis() + 5000)));
    }
}
